package com.lzy.cloud.order.controller;

import com.lzy.cloud.order.remote.BaseApi;
import com.lzy.cloud.order.request.ticket.train.OrderBookingAppRequest;
import com.lzy.cloud.order.response.MemberToken;
import com.lzy.cloud.order.response.ticket.train.TicketTrainResponse;
import com.lzy.cloud.order.service.impl.OrderInfoTicketTrainServiceImpl;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:房车销售订单子表
 * @author: liyun
 * @create: 2018-07-05 13:49
 */
@RestController
@RequestMapping("/order/ticket/train")
public class OrderInfoTicketTrainController {
    @Autowired
    private OrderInfoTicketTrainServiceImpl orderInfoTicketTrainService;
    @Autowired
    private BaseApi baseApi;

    /**
     * 新增房车销售订单子表
     * @param request
     * @return
     */
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public TicketTrainResponse create(@RequestHeader("token") String token, OrderBookingAppRequest request) {
        Ensure.that(token).isNotNull("00000002");
        MemberToken memberToken = DozerUtils.map(baseApi.isMemberLogin(token).getResult(),MemberToken.class);
        Ensure.that(memberToken).isNotNull("00001033");
        TicketTrainResponse response = orderInfoTicketTrainService.create(token, request, memberToken.getId());
        return response;
    }

}
